package org.luxor.cloud.gateway.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.ToStringSerializer;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;


/**
 * 网关API路由定义
 *
 * @author administrator @date 2020-10-29 14:18:48
 */
@Data
@TableName("tb_gateway_route")
public class GatewayRouteEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.ID_WORKER)
    @JSONField(serializeUsing = ToStringSerializer.class)
    @NotNull(message = "routId，不能为空")
    private Long routeId;

    /**
     * 路由路径(如：/users/info)
     */
    @NotBlank(message = "routePath，不能为空")
    private String routePath;

    /**
     * 路由版本(如：v1)
     */
    @NotBlank(message = "routeVersion，不能为空")
    private String routeVersion;

    /**
     * 路由方法(必须全大写,如：GET|POST|DELETE|PUT|PATCH)
     */
    @NotBlank(message = "routeMethod，不能为空")
    private String routeMethod;

    /**
     * 路由描述
     */
    private String routeDescription;

    /**
     * 目标应用ID (如: luxor-cloud-users)
     */
    @NotBlank(message = "targetId，不能为空")
    private String targetId;

    /**
     * 目标接口URI (如: lb://luxor-cloud-users/info)
     */
    @NotBlank(message = "targetUri，不能为空")
    private String targetUri;

    @ApiModelProperty(value = "排序")
    private Integer orderNum;

    /**
     * 发布状态(0-待发布；1-已发布；2-已下线；)
     */
    private Byte status;

    /**
     * 连接超时时间(默认5秒)
     */
    private Short connectionTimeout;

    /**
     * 最大连接数(默认250)
     */
    private Short maxConnections;

    /**
     * 启用访问权限控制？(0-不启用；1-启用)
     */
    private Boolean authEnabled;

    /**
     * 权限范围(basics,user_details,party)
     */
    private String authScope;

    /**
     * 权限码
     */
    private String authAuthorities;

    /**
     * 启用商业限制?（0-不启用；1-启用）
     */
    private Boolean validEnabled;

    /**
     * 限制生效日期(单位:天
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date validEffectTime;

    /**
     * 限制逾期日期(单位:天)
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date validExpireTime;

    /**
     * 限制最大可访问次数(-1代表无限制)
     */
    private Long validTotalRequests;

}
